package com.zte.purchase.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.purchase.dao.IProductTypeDao;
import com.zte.purchase.model.CType;
import com.zte.purchase.model.CTypeCondition;
import com.zte.purchase.server.IProductTypeService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductTypeService implements IProductTypeService {

    @Autowired
    private IProductTypeDao typeDao;

    @Override
    public boolean addProductType(CType type) {

        return typeDao.addProductType(type);

    }

    @Override
    public boolean updateCType(CType type) {

        return typeDao.updateCType(type);

    }

    @Override
    public CType findOneCType(String typeId) {

        return typeDao.findOneCType(typeId);

    }

    @Override
    public PageModel<CType> queryTypeList(PageModel<CType> pageModel,CTypeCondition conn) {
        int pageNum = pageModel.getPageNum()<=1?1:pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum,pageSize);

        List<CType> cTypes = typeDao.queryTypeList(conn);
        PageInfo<CType> info = new PageInfo<CType>(cTypes);
        return PageModel.getPageModel(pageModel,info);
    }
}
